<?php require_once 'header.php';?>    
<!-- DataTables Responsive CSS -->
    <link href="sb2/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet">
        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                        <?php echo XXF_BACK?>
                        当前试卷的试题管理
                        <br>新加评测试题题目：<input name="x" id="title">&nbsp;<button onclick="pcsjadd()">新增</button>
                        <input name="x" id="pcsjid" value="<?php echo $pcsjid?>" type="hidden">
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                        	<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>评测试卷题目</th>
                                        <th>选项</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                	<?php
                                	$i=0;
                                	foreach ($result as $row){$i++;
                                	?>
                                    <tr class="<?php echo $i%2==0?"even":"odd";?> gradeA">
                                    	<td><?php echo $i;?></td>
                                        <td><?php echo $row['title']?></td>
                                        <td><a href="javascript:xxadd(<?php echo $row['id']?>);" ><i class="fa fa-fw fa-plus-square"></i></a><br>
                                        <?php 
                                        $xx=xdb::getInstance()->getarray("select * from pingceshijuansub where pcsjtid=".$row['id']);
                                        foreach ($xx as $x){
                                            echo '<a href="javascript:xxdel('.$x['id'].');" ><i class="fa fa-fw fa-minus-square"></i></a>['.$x['fen']."] ".$x['sub']."<br>";
                                        }
                                        ?>
                                        </td>
                                        <td>删除</td>
                                    </tr>
                                	<?php 
                                	}
                                	?>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
             </div>
        </div>
        <!-- /#page-wrapper -->
  </div>
        <!-- DataTables JavaScript -->
<?php require_once 'bottom.php';?>
    <script src="sb2/vendor/datatables/js/jquery.dataTables.js"></script>
    <script src="sb2/vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="sb2/vendor/datatables-responsive/dataTables.responsive.js"></script>
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
            responsive: true,
            "aaSorting": [[ 0, "asc" ]],
            "aLengthMenu": [ 100,50,25,10]
        });
    });
    function pcsjadd(){
    	$pcsjname=$.trim($("#title").val());
    	if($pcsjname.length<2){
        	$.xalert("请将信息填写完整！");
        }else{
        	$.xtodb("add","pingceshijuantitle",$("[name='x']"),"pcsjid_title",function(data){//增加数据，数据库，操作相关form，验证列不能重复，回调
        		if(data==0){
        			$.xloading(0);
        			$.xalert("添加失败");
        		}else if(data==1){
        			window.location.reload();
        		}else{
					console.log(data);
            	}
        	});
        }
    }
    function xxadd(id){
        $.xconfirm("<input name='x2' id='pcsjtid' value='"+id+"' type='hidden'>"+
            "内容:<input name='x2' id='sub'><br>分值:<input name='x2' id='fen' type='number' value='5' style='width:40px;'>"
        ,function(tf){
			if(tf){
				$.xtodb("add","pingceshijuansub",$("[name='x2']"),"pcsjtid_sub_fen",function(data){//增加数据，数据库，操作相关form，验证列不能重复，回调
	        		if(data==0){
	        			$.xloading(0);
	        			$.xalert("添加失败");
	        		}else if(data==1){
	        			window.location.reload();
	        		}else{
						console.log(data);
	            	}
	        	});
			}
        });
    }
    function xxdel(id){
		$.xconfirm("是否确定删除该选项？",function(tf){
			if(tf){
				$.xtodb("del","pingceshijuansub",{},id,function(data){//删除，数据库，空，数据行id，回调
					if(data==0){
						$.xloading(0);
						$.xalert("删除失败");
					}else{
						window.location.reload();
					}
				});
			}
		});
    }
	</script>